1

I am working on contact page where the client can enter the postcode which will take them to google maps for directions to the company, the problem which i am having is although the hyperlink is set to target_blank but still the window opens on the back hand instead of opening in front of the website page. I have no idea why it opens on the back hand and focus is on the current page instead of moving it to google map page

 <a href="#" target="_blank"> <img alt="" src="/images/contactUs/directionbtn.png" onclick="return openDirections(1);" /></a> <script type="text/javascript"> function openDirections(NumVal) { if (NumVal == 1) { if (document.getElementById("<%=txtPostcode.ClientID%>").value == "") { alert("PostCode can not be blank"); document.getElementById("<%=txtPostcode.ClientID%>").focus(); return false; } else { var regPostcode = /^([a-zA-Z]){1}([0-9][0-9]|[0-9]|[a-zA-Z][0-9][a-zA-Z]|[a-zA-Z][0-9][0-9]|[a-zA-Z][0-9]){1}([ ])([0-9][a-zA-z][a-zA-z]){1}$/; var tempURL = document.getElementById("<%=txtPostcode.ClientID%>").value; if (regPostcode.test(tempURL) == false) { alert("Please Enter a Valid PostCode"); document.getElementById("<%=txtPostcode.ClientID%>").focus(); return false; } else { var url = 'http://maps.google.co.uk/maps?saddr={' + $('#<%=txtPostcode.ClientID%>').val() + '}&daddr=&daddr=646+Preston+Rd,+Clayton-le-Woods,+Chorley+PR6+7EH,+United+Kingdom&iwloc=1&dq=Tangent+Design'; document.location = url; return true; } } } </script> 
2
  • What does "opens on the back hand" mean? And this looks like JavaScript to me! Commented May 23, 2011 at 15:44
  • the page doesnt loads in front of the website like it should Commented May 23, 2011 at 15:45

4 Answers 4

1

Try window.open(url); instead of of document.location = url;

Sign up to request clarification or add additional context in comments.

7 Comments

window.open(url); opens the same page twice instead of going to google maps
Then your function might be called twice. You can check this easily by adding alert("This popup should only appear once."); in your openDirections function.
Btw, from where is openDirections called?
have included <a> in the question
Try removing the surrounding <a> tag and just use this html: <img alt="" src="/images/contactUs/directionbtn.png" onclick="return openDirections(1);" /> and also change document.location = url; return true; to document.location = url; return false;
|
1

All I see you doing is setting the url of the current window. Maybe try using something like this to open a new window instead.

window.open('url to open',) 

in place of document.location = url

8 Comments

window.open(url); opens the same page twice instead of going to google maps
@Muhammad Awais If it is opening the same page, that says you might be setting the url incorrectly.
i just changed it to window.open(url);
@Muhammad Awais I just tried it. Here is the jsfiddle. It opens to google maps just fine. Something else is amiss here. jsfiddle.net/mEw6J
i tried this, which doesnt works var url = 'maps.google.co.uk/maps?saddr={' + $('#<%=txtPostcode.ClientID%>').val() + '}&daddr=&daddr=646+Preston+Rd,+Clayton-le-Woods,+Chorley+PR6+7EH,+United+Kingdom&iwloc=1&dq=Tangent+Design'; window.open(url);
|
1

Each browser can be configured to handle how new pages are opened. Take a look at the preferences in the browser you are using, and see if that is the behavior that you currently have configured.

12 Comments

i have checked on all the browsers , the result is same
does it open in a tab or a seperate window?
this is probably a configuration in your browser. did you try looking in the config of whatever browser you are using? In IE 8, what i have to use at work, it is under Tools -> Internet Options -> Settings (under the Tabs heading). In that window, you will see a setting, always switch to new tabs when they are created; check it.
the new tab box is selected .. I m using chrome
Looks like chrome may not support opening in the foreground by default - google.com/support/forum/p/Chrome/…. I don't have it at work to test.
|
0

I think this is what you are looking for:

var x = window.open(URL, 'name', '...'); x.focus(); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.