Hey all,

I'm working on a project combining a javascript bookmarklet and a php script that lets users mail the url of the site they are currently browsing to their email address.

I had a PHP issue solved over in the PHP forum:

http://www.daniweb.com/forums/thread202375.html

But now I have a new bug. The script/bookmarklet works fine on Chrome and Firefox in Windows and opens a popup without taking the user away from the page, but on a mac in Firefox, it takes the user away from the page they are browsing AND opens the popup. The new page is a print out of the javascript bookmarklet. Has anybody seen this before? Here is the bookmarklet as it is now:

javascript: 
var url = encodeURIComponent(window.location.href); 
var user = 'youremail@domain.com'; 
var title = document.title; 
alert(url + '\n' + title); window.open('http://www.playground.nudebeachfilms.org/mailurl/mail.php?url=' + url + '&user=' + user + '&title=' + title,'mywindow','width = 400, height = 250');

Also, after using the bookmarklet, all of my "restore down" browser windows are 400 by 250. Is there a way to open up a popup of a certain size and not have the size saved as the default size for non-full-screen browser windows?

Recommended Answers

All 2 Replies

Try using this popup.js:

popup.js

var win;
var popUp = function( mypage, myname, w, h ) {

   var winW = (( screen.width ) ? screen.width : (( window.clientWidth ) ? window.clientWidth : window.innerWidth ));

   var winH = (( screen.Height ) ? screen.Height : (( window.clientHeight ) ? window.clientHeight : window.innerHeight ));

   w = (( w ) ? (( winW ) - w ) : winW );
   h = (( h ) ? (( winH ) - h ) : winH );
   var opened = "active";

   var winprops = "";
   winprops += "width=" + w;
   winprops += ", height=" + h;
   winprops += ", top=0, left=0";
   winprops += ", scrollbars=yes";
   winprops += ", menubar=yes";
   winprops += ", toolbar=yes";
   winprops += ", resizable=yes"; 
   winprops += ", location=yes";
   
   if ( window.status === mypage ) {
      if ( typeof win !== "undefined" ) {
         if ( typeof (( win.opener ) ? win.opener : win.parent ) !== "undefined" ) { 
         win.focus();
         return false;
         } else {
         win = window.open( mypage, target = opened, myname, winprops );
         win.focus();
         return false;
         }
      } else { 
      win = window.open( "", target = opened, myname, winprops );
      win.focus();
      return false; 
      }      
   } else if ( window.status !== mypage ) {
      if ( typeof win !== "undefined" ) {
         if ( typeof (( win.opener ) ? win.opener : win.parent ) !== "undefined" ) {
         win.location.href = mypage;
         window.status = mypage;
         win.focus();
         return false;
         } 
      }
   } win = window.open( mypage, target = opened, myname, winprops );
     window.status = mypage;
     return false;
};

call the popup opener in your page:

<script type="text/javascript">
<!--

var testFunc = function() { 
var url = encodeURIComponent(window.location.href);
 
var user = 'youremail@domain.com';
 
var title = document.title; 

// alert(url + '\n' + title); 

//You can open a new window with this call ==>

popUp('http://www.playground.nudebeachfilms.org/mailurl/mail.php?url=' + url + '&user=' + user + '&title=' + title, 'mywindow', 400, 250 );
};
window.onload = testFunc;
//-->
</script>

hope it helps...

On the end, you need to ensure that that the bookmarklet returns null, leaving the browser on the same page. This can be done by adding (); instead of ; . You might also want to add a wrapper function

javascript:(function(){ /*code here*/ })();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.