homepage Welcome to WebmasterWorld Guest from 54.161.192.130
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
JS - Open in new window
Simplest way to do this?
Nick_W

WebmasterWorld Senior Member nick_w us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 204 posted 12:02 pm on Oct 3, 2002 (gmt 0)

Hi all,

How do I make a link like this open in a new window?

<a href="javascript:self.location='page.html';">some page</a>

thanks

Nick

 

Nick_W

WebmasterWorld Senior Member nick_w us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 204 posted 12:21 pm on Oct 3, 2002 (gmt 0)

er....

and make the window that remains still the same as where they left it!

Heres what I managed to work out myself:

<a href="javascript:window.open('page.html');">page</a>

but the window that's left behind just has a blank page with:

object[object]

or something on it?

Nick

SethCall

10+ Year Member



 
Msg#: 204 posted 2:54 pm on Oct 3, 2002 (gmt 0)

Well, I tried what you said, and indeed, it does do just that.

Did you notice that your window that says [object] also has javascript:window.open("blah.html") in it?

So, what happened was, when you clicked your link, the webpage actually *became* just "javascript:window.open("blah.html");" (try mozilla to see this. I believe IE does something different).

And, that line still got executed, and the new window, blah.html, opened as well.
Right? Hehe Im not totally clear on all of this.

So, instead, I made a one-line fuction called doit() with just
window.open("blah.html"); in it
and the href looks like:

<a href = "javascript:doit()">Click y0</a>

And it worked great!

SethCall

10+ Year Member



 
Msg#: 204 posted 2:55 pm on Oct 3, 2002 (gmt 0)

Did you notice that your window that says [object] also has javascript:window.open("blah.html") in it?

I mean, the navigation bar of the initial window has javascript:window.open("blah.html") in it :).

k just clarifying

Nick_W

WebmasterWorld Senior Member nick_w us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 204 posted 3:07 pm on Oct 3, 2002 (gmt 0)

Right thanks!

Can I see the function?
And would I be able to call it with different urls each time?

Cheers

Nick

dingman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 204 posted 3:14 pm on Oct 3, 2002 (gmt 0)

<a href="http://www.mysite.com/other.html" onclick="window.open(this.href);return false;">another page (new window)</a>

Spider-friendly, 'cuz the href attribute is there and gets used. No change to the current window because if the onclick handler returns false, the browser isn't supposed to follow the link.

<added>Also degrades well, since if js is disabled, the browser still has a link to follow, and will.</added>

[edited by: dingman at 3:24 pm (utc) on Oct. 3, 2002]

SethCall

10+ Year Member



 
Msg#: 204 posted 3:23 pm on Oct 3, 2002 (gmt 0)

Can I see the function?

function doit(){
window.open('view.php');
}

Now, here is another way: (I am not very sure about the whole "spider-friendly" thing, because I dont even know what that is ;))

<a href = "javascript:windowHandle = window.open('view.php','windowname','width=500,height=500,location=yes'); windowHandle.focus();">Click y0</a>

the windowHandle.focus is quite necessary...

Nick_W

WebmasterWorld Senior Member nick_w us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 204 posted 3:24 pm on Oct 3, 2002 (gmt 0)

Great, thanks dingman ;)

How do I make it spider un-friendly?

Nick

dingman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 204 posted 3:29 pm on Oct 3, 2002 (gmt 0)

Nick, do you mean "I want spiders to not follow this link, how do I do that?" or "Dingman, you fool, you're overlooking something that makes a javascript: pseudo-url perfectly OK for spiders?"

If the former, my guess would be that instead of
<a href="http://www.mysite.com/other.html" onclick="window.open(this.href);return false;">another page (new window)</a>

you could do
<a href="doesn't matter as long as onclick returns false" onclick="window.open('other.html');return false;">another page (new window)</a>

If the latter, enlighten me :)

Nick_W

WebmasterWorld Senior Member nick_w us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 204 posted 3:37 pm on Oct 3, 2002 (gmt 0)

hehe, no you're not a fool!

I just don't want the spiders to follow the link to the popup. It's for affiliate links and I don't want them draining PR.

Will what you said in your last post be okay for that criteria?

Thank,

Nick

dingman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 204 posted 3:49 pm on Oct 3, 2002 (gmt 0)

As far as I know, yes. I'd probably make the "href" point to an internal page with an explanation for the users who have javascript turned off, to keep from completely confusing them.

I'm a lot less experienced than you are, and search engine behavior is not something I'm used to thinking about, let alone knowledgable about. September 10th, I didn't even know what "page rank" was. Might want to ask whether googlebot or any of the other search engine spiders have js interpreters. If so, I don't think anything we've looked at will hide from them.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved