Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 711419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:43:59+00:00 2026-05-14T04:43:59+00:00

I’m refactoring a website using MVC. What was a set of huge pages with

  • 0

I’m refactoring a website using MVC. What was a set of huge pages with javascript, php, html etc etc is becoming a series of controllers and views. I’m trying to do it in a modular way so views are split in ‘modules’ that I can reuse in other pages when needed

eg.
“view/searchform displays only one div with the searchform
“view/display_events displays a list of events
and so on.

One of the old pages was supposed to load a google map with a marker on it.

Amongst the rest of the code, I can identify the relevant bits as follows

<head>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=blablabla" type="text/javascript"></script>

<script type="text/javascript">
//<![CDATA[
function load() {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        var point = new GLatLng(<?php echo ($info->lat && $info->lng) ? $info->lat .",". $info->lng : "51.502759,-0.126171"; ?>);
        map.setCenter(new GLatLng(<?php echo ($info->lat && $info->lng) ? $info->lat .",". $info->lng : "51.502759,-0.126171"; ?>), 15);
        map.addControl(new GLargeMapControl());
        map.addControl(new GScaleControl());
        map.addOverlay(new GMarker(point));
        var marker = createMarker(point,GIcon(),"CIAO");
        map.addOverlay(marker);
    }
}
//]]>
</script>
</head>

…then

<body onload="load()" onunload="GUnload()">

…and finally this div where the map should be displayed

<div id="map" style="width: 440px; height: 300px"> </div>

Don’t know much about js, but my understanding is that

a) I have to include the scripts in the view module I’m writing (directly in the HTML? I would prefer to load a separate script)

b) I have to trigger that function using the equivalent of body onload… (obviously there’s no body tag in my view. In my ignorance I’ve tried div onload=…. but didn’t seem to be working 🙂

What do you suggest I do?
I’ve read about window.onload but don’t know what’s the correct syntax for that.

please keep in mind that other parts of the page include other js functions (eg, google adsense) that are called after the footer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:43:59+00:00Added an answer on May 14, 2026 at 4:43 am

    You can attach a handler to the window load event with js, so you don’t need the markup.

    // crossbrowser event binding from http://www.quirksmode.org/js/eventSimple.html
    //function addEventSimple(obj,evt,fn) {
    //    if (obj.addEventListener)
    //      obj.addEventListener(evt,fn,false);
    //    else if (obj.attachEvent)
    //      obj.attachEvent('on'+evt,fn);
    //}
    
    // using Google API's event functions
    GEvent.addDomListener(window, "load", load);
    GEvent.addDomListener(window, "unload", GUnload);
    
    function load() {
        // your load function
    }
    

    Drop that in a script tag on your view and the load function will be called once the window is loaded.

    The google API probably also provides a way to attach the load event, but I’m not familiar with it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have thousands of HTML files to process using Groovy/Java and I need to
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.