Jump to content

Creating a Firefox extension (javascript problem)


Duncman

Recommended Posts

All right, so I want to make a Firefox extension and so far I've got it all sorted. Apart from the javascript part that is.

 

What I'm trying to do is re-create the Safari image viewing ways when you open just a image file. When you open a picture, or click on a link that is just a picture, it displays the image without any spacing on the top and left sides, and is always full size. Here is an example (click to see the full size).

 

Picture%201.jpg

 

<a href="http://www.mystdesigns.co.uk/uploads/Picture%201.jpg"><img src="http://www.mystdesigns.co.uk/uploads/Picture%201.jpg" width="500px" height"300px"></a>

 

As you can see there is no margin above or to the left of the picture, and is zoomed in regardless of the window size.

 

 

Is there any chance someone could create this for me? Or guide me through making it as I really should learn javascript.

 

The zoom problem doesnt need to be sorted. I'm not too fussed about that, but any help in creating the anti-gap code would be much appreciated. As far as I can see, it would entail getting the URL, checking to see if it ended in JPG or GIF or whatever (I'd assume applying it to all images rather than seeing if the URL finished with JPG would mean all the images on a page would be moved) and then applying a CSS rule to give it negative margins and shifting the image up.

 

 

Any help would be much appreciated.  :)

Link to comment
Share on other sites

ok, so after having a go at this myself for a little while, ive so far got this.

 

 

 

var is_input = document.URL.indexOf('.jpg');

if (is_input != -1)
{ 
addr_str = document.URL.substring(is_input+1);
}


if (addr_str == 'jpg')
{
document.write ("<style>body {margin:0px}</style>");
}

else
{
}

 

 

As far as I can tell from this code, its looking in the URL for .jpg, then something is going on next, then if that addr_str is equal to jpg, it should set the page margins to 0, else it does nothing.

 

Now theres 2 problems with this. When testing this, the error console in Firefox said that the first line is invalid somehow, or there was some problem with it. The second problem is that I'm trying to apply a style to HTML, where HTML wouldnt be displayed. Does anyone know how to get it to set the margins on an image to 0?

Link to comment
Share on other sites

you can do this:

<script>
    document.getElementById('idInPictureTag').style.margin =0;
    document.getElementById('idInPictureTag').style.padding =0;
    //you might also have to do
    document.getElementById('idInPictureTag').vspace =0;
    document.getElementById('idInPictureTag').hspace =0;
</script>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.