March 23, 2012

window.open() does nothing in jquery mobile?

Question by PathOfNeo

i can’t use target=_blank because my actions are build dynamically, example: when user clicks on the link, i catch it with .click(function(event), than ajax api is called and then in the callback i have the url where to go.

Now the problem:

window.location = mylink; // WORKS – OK!
window.open(mylink); // DOES NOT WORK – NOT OK!

why?

I need to open a new window because mylink is a link to a pdf file, and when using window.location the pdf file is correctly viewed, but,..without any back navigation controls of the browser. It’s a mobile webapp, and i use jquery mobile.

Too bad on the internet many others have the pdf viewer problem but no one has solved it, so i figured out to open a new window and pass the pdf link there. This way my parent window would stay untouched. Otherwise, you have to kill the current session and open safari again..

Answer by Starx

If you want to open a dialog/popup in jQuery Mobile you have to use an attribute data-rel="dialog" and the href attribute must point to a URL you want to load

<a href="yourpage.html" data-role="button" data-rel="dialog">Open dialog</a>

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!