Skip to content

Instantly share code, notes, and snippets.

@grandmanitou
Created August 18, 2020 13:58
Show Gist options
  • Save grandmanitou/376526c90eb070cbfa1d01a1aa56e421 to your computer and use it in GitHub Desktop.
Save grandmanitou/376526c90eb070cbfa1d01a1aa56e421 to your computer and use it in GitHub Desktop.
Create preview button next to an url input, open in new tab -- Bootstrap 4 / Laravel
$(document).on('click', '.btn-preview-url', function(e) {
e.preventDefault();
let element = $(this).data('src');
let url = $(element).val();
if (url !== '') {
window.open(url, '_blank');
}
return false;
});
<?php
<div class="form-group">
<label for="website">{{ __('Website') }}</label>
<div class="input-group">
<input type="text" id="website" name="website" value="{{ old('website') }}" class="form-control @error('website') is-invalid @enderror" placeholder="{{ __('Website') }}">
<div class="input-group-append">
<button class="btn btn-outline-secondary btn-preview-url" type="button" data-src="#website" class="">{{ __('Preview in new tab') }} <i class="fa fa-external-link"></i></button>
</div>
</div>
@error('website') <div class="invalid-feedback">{{ $message }}</div> @enderror
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment