Window.open Not woking in safari(its very urgent)

Hi:

1 I am using javascript window.open() method to open new window, it works well inIE,Firefox but not working in safari.

2 I have problem on firefox, image control never displays image in firefox.I have mentioned the code below.Can any one send me suggestions to solve these issues

Javascript code:

<html>
<head>

</head>
<body>
<a href=“javascript:window.open(‘getkeycode.html’,‘null’,‘height=500,width=500,status=no, toolbar=no,menubar=no,location=no’)”>
<img id=“image” height=“200” width=“200” alt=“Hi” src=“URL”>
</a>

</body>

</html>

Thanks

It works in Safari 3.1.2 on Mac OS 10.5

This is not the cross-browser way of opening a new window.
Here is the solution.

<a href="getkeycode.html" onclick="javascript:window.open('getkeycode.html','null','height=500,width=500,status=no, toolbar=no,menubar=no,location=no');return false">Link TEXT or IMAGE HERE</a>

You don’t need a label inside the onclick. The onclick already identifies that it is JavaScript. There are also a couple of other changes you can make that will make the onclick code more portable so that you don’t need to change it if you have multiple links that you want to use it with.

<a href="getkeycode.html"
onclick="window.open(this.href,'_blank','height=500,width=500,status=no, toolbar=no,menubar=no,location=no');return false"
>Link TEXT or IMAGE HERE</a>

True.

Portable???

Portable meaning you can use the same code for different situations, although it’s bad enough that the code referred to is embedded inline. By replacing the explicit url with this.href he can just copy this on other elements and not retype the same link over and over.

Portable means cross-broser.

However.

I never thought of the this.href solution. Have to test how it is handled by the different browsers. If they all accept it, this is GREAT. :slight_smile:

View Post
There are also a couple of other changes you can make that will make the onclick code more portable so that you don’t need to change it if you have multiple links that you want to use it with.

He clearly mentions what he means by portable (which I bolded and underlined for you). What he has suggested does not make any difference cross-browser wise, and all modern user agents would support the legacy DOM property href on the current HTMLElement.

All modern? What about older, not everybody surfs with the last browser?
For example IE 8 is on the way, and ppl still surf with IE 5.5.

It does support this.href, since its a legacy dom property as mentioned. Are you not able to grab a copy and test out for yourself?

This is what I mentioned in a first place. If tests show it works, then it is good.

Actually you are just speaking for the sake of it, not reading the posts on the first place.

You shouldn’t need to test ‘this.href’ on browsers, as 95%+ of them support this, since these are LEGACY DOM 0 PROPERTIES which have been supported for YEARS and YEARS.

I think this is off topic. Thank you so far for your replies.

It’s not off topic, as it relates to Javascript implementations on user agents which have access to DOM properties that enable them to manipulate documents in various ways. As I said in the other thread, please pickup a basic JS book and learn before making useless/false statements.

Thank you once again.

this.href predates the DOM and is supported on all javascript capable browsers, having been available since the beginnings of javascript.

Check out the JavaScript 1.0 Authoring Guide and look in the Statements section.

Try the following out on a Netscape 2.0 browser.


<a href="somelink.html" onclick="alert(this.href)">Test</a>

The above won’t work on Netscape 1.0 and the original Mosaic browser, only because javascript wasn’t invented yet.