You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Lidija Dolinar <li...@gmail.com> on 2013/11/26 07:33:35 UTC

How to refresh a zone containing document.write()?

Hi,

I need to display a zone, containing javascript code that contains
document.write().

I created an example - here is the relevant code:

        <t:zone t:id="timeZone" id="timeZone">
...
            <script type="text/javascript">
                var currentdate = new Date();
                var datetime = "Current time (JS): " + currentdate.getDay()
+ "."+currentdate.getMonth() + "." + currentdate.getFullYear() + " " +
currentdate.getHours() + ":" + currentdate.getMinutes() + ":" +
currentdate.getSeconds();

                document.write(datetime);
            </script>
...
        </t:zone>


It doesn't matter whether I call:

ajaxResponseRenderer.addRender(timeZone)

or if I return

return request.isXHR() ? smsZone.getBody() : null;

The result is always the same - ONLY datetime is displayed - only code in
the JavaScript tags. Everything else is discarded.

How can I properly display zone containing javascript's document.write()?

I cannot control the contents of the Javascript (it's being returned from
an ad server - it displays an ad).

Regards,
Lidija

Re: How to refresh a zone containing document.write()?

Posted by Lidija Dolinar <li...@gmail.com>.
After discussing it with our marketing staff it turns out that we don't
need to display the ad on demand.

So the solution is to load the ad at page load time and display it in a
hidden div. When it needs to be displayed, the div containing the ad is
simply shown.

Thank you for help!

Regards,
Lidija


On Wed, Nov 27, 2013 at 8:24 AM, Dmitry Gusev <dm...@gmail.com>wrote:

> Can you put your Ad div to IFrame ?
>
>

Re: How to refresh a zone containing document.write()?

Posted by Dmitry Gusev <dm...@gmail.com>.
Can you put your Ad div to IFrame ?


On Wed, Nov 27, 2013 at 11:20 AM, Lidija Dolinar <li...@gmail.com>wrote:

> Thiago, thank you for your suggestion.
> The contents of OAS_AD JavaScript function is returned from an ad server
> and I have no control over it.
>
> I tried to use the Tapestry.ZONE_UPDATED_EVENT, but to no avail.
>
> TML contents of the example:
>
> <t:zone t:id="timeZone" id="timeZone">
>     Current time: ${time}
> </t:zone>
>
> <!-- Ad -->
> <div id="smsAdvert">
>     <script type="text/javascript">
>      function displayAd() {
>          OAS_AD('Bottom1');
>      }
>     </script>
> </div>
> <!-- /Ad -->
>
>
> Java:
>
>     @AfterRender
>     void afterRender() {
>
> javaScriptSupport.addScript("jQuery('#%s').on(Tapestry.ZONE_UPDATED_EVENT,
> function() { displayAd() });", timeZone.getClientId());
>     }
>
>
> displayAd() function is triggered, ad is being displayed, but the effect is
> the same as before - on the whole page only ad is displayed, any other
> contents is lost.
>
> One possible solution that I could think of was to create a separate page
> to retrieve the ad and then include that page's HTML with an AJAX request.
> But this assumption proved to be wrong, this also doesn't work - I'm still
> playing around with it to see if there's any way to make it work.
>
> It seems I'm stuck. Any other ideas?
>
> Lidija
>
>
>
>
> On Tue, Nov 26, 2013 at 11:29 AM, Thiago H de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
>
> > On Tue, 26 Nov 2013 04:33:35 -0200, Lidija Dolinar <lidija.ldo@gmail.com
> >
> > wrote:
> >
> >  Hi,
> >>
> >
> > Hi!
> >
> >
> >  I need to display a zone, containing javascript code that contains
> >> document.write().
> >>
> >
> > You know using that function is not recommended at all, right? ;) But
> then
> > I read that it's being returned from somewhere else . . .
> >
> >
> >  How can I properly display zone containing javascript's
> document.write()?
> >>
> >
> > The proper way of calling JavaScript code after a Zone update is to
> listen
> > to the Tapestry.ZONE_UPDATED_EVENT event from the element which is the
> Zone.
> >
> > --
> > Thiago H. de Paula Figueiredo
> > Tapestry, Java and Hibernate consultant and developer
> > http://machina.com.br
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>



-- 
Dmitry Gusev

AnjLab Team
http://anjlab.com

Re: How to refresh a zone containing document.write()?

Posted by Lidija Dolinar <li...@gmail.com>.
Thiago, thank you for your suggestion.
The contents of OAS_AD JavaScript function is returned from an ad server
and I have no control over it.

I tried to use the Tapestry.ZONE_UPDATED_EVENT, but to no avail.

TML contents of the example:

<t:zone t:id="timeZone" id="timeZone">
    Current time: ${time}
</t:zone>

<!-- Ad -->
<div id="smsAdvert">
    <script type="text/javascript">
     function displayAd() {
         OAS_AD('Bottom1');
     }
    </script>
</div>
<!-- /Ad -->


Java:

    @AfterRender
    void afterRender() {
    javaScriptSupport.addScript("jQuery('#%s').on(Tapestry.ZONE_UPDATED_EVENT,
function() { displayAd() });", timeZone.getClientId());
    }


displayAd() function is triggered, ad is being displayed, but the effect is
the same as before - on the whole page only ad is displayed, any other
contents is lost.

One possible solution that I could think of was to create a separate page
to retrieve the ad and then include that page's HTML with an AJAX request.
But this assumption proved to be wrong, this also doesn't work - I'm still
playing around with it to see if there's any way to make it work.

It seems I'm stuck. Any other ideas?

Lidija




On Tue, Nov 26, 2013 at 11:29 AM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Tue, 26 Nov 2013 04:33:35 -0200, Lidija Dolinar <li...@gmail.com>
> wrote:
>
>  Hi,
>>
>
> Hi!
>
>
>  I need to display a zone, containing javascript code that contains
>> document.write().
>>
>
> You know using that function is not recommended at all, right? ;) But then
> I read that it's being returned from somewhere else . . .
>
>
>  How can I properly display zone containing javascript's document.write()?
>>
>
> The proper way of calling JavaScript code after a Zone update is to listen
> to the Tapestry.ZONE_UPDATED_EVENT event from the element which is the Zone.
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: How to refresh a zone containing document.write()?

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 26 Nov 2013 04:33:35 -0200, Lidija Dolinar <li...@gmail.com>  
wrote:

> Hi,

Hi!

> I need to display a zone, containing javascript code that contains
> document.write().

You know using that function is not recommended at all, right? ;) But then  
I read that it's being returned from somewhere else . . .

> How can I properly display zone containing javascript's document.write()?

The proper way of calling JavaScript code after a Zone update is to listen  
to the Tapestry.ZONE_UPDATED_EVENT event from the element which is the  
Zone.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org